package com.hsy.linemoney.apiservice;

import com.deparse.dpframe.tools.utils.DPGsonUtil;
import com.hsy.linemoney.R;
import com.hsy.linemoney.requests.RequestTask;
import com.hsy.linemoney.utils.ToastUtil;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.List;

/**
 * 投标版相关
 * Created by MartinKent on 2016/9/26.
 */
public class BidService extends BasicService<JSONArray> {
//    获取投标版列表
    public void getFromCurrencyToCurrencyOrder(final String fromCurencyCd, final String toCurrencyCd, final Callback<FromCurrencyToCurrencyOrderResult> callback, boolean... clearData) {
        if (null != clearData && clearData.length > 0 && clearData[0]) {
            DataHolder.mFromCurrencyToCurrencyOrderResult = null;
        }
        if (null != DataHolder.mFromCurrencyToCurrencyOrderResult) {
            if (null != callback) {
                callback.onSuccess(0, DataHolder.mFromCurrencyToCurrencyOrderResult);
            }
            return;
        }
        String api = "/LmBusinessServices-portlet.order/get-from-currency-to-currency-order";
        JSONObject params = ParamsMaker.newInstance()
                .add("fromCurrencyCd", fromCurencyCd)
                .add("toCurrencyCd", toCurrencyCd)
                .add("userId", LineMoneyContext.getLoggedUser().getUserId())
                .add("language", LineMoneyContext.getLocalLanguagePair().locale.getLanguage())
                .get();
        invoke(0, api, params, new Callback<JSONArray>() {
            @Override
            public void onSuccess(int what, JSONArray result) {

                try {
                    DataHolder.mFromCurrencyToCurrencyOrderResult = DPGsonUtil.fromJson(result.get(0).toString(), FromCurrencyToCurrencyOrderResult.class);
                    if (null != callback) {
                        callback.onSuccess(0, DataHolder.mFromCurrencyToCurrencyOrderResult);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                    callback.onError(what, 0, e.getLocalizedMessage(), e);
                }
            }

            @Override
            public void onError(int what, int type, String msg, Exception e) {
                if (e instanceof RequestTask.StatusCodeException) {
                    ToastUtil.showToast(msg);
                } else {
                    ToastUtil.showToast(R.string.txt_network_failure);
                }
                if (null != callback) {
                    callback.onError(what, 0, msg, e);
                }
            }
        });
    }

    public static class FromCurrencyToCurrencyOrderResult {
        private Status status;

        private List<Value> value;

        public void setStatus(Status status) {
            this.status = status;
        }

        public Status getStatus() {
            return this.status;
        }

        public void setValue(List<Value> value) {
            this.value = value;
        }

        public List<Value> getValue() {
            return this.value;
        }

        public class Status {
            private String message;

            private String code;

            public void setMessage(String message) {
                this.message = message;
            }

            public String getMessage() {
                return this.message;
            }

            public void setCode(String code) {
                this.code = code;
            }

            public String getCode() {
                return this.code;
            }

        }

        public static class Value {
            private String durationTypeCd;

            private String serviceFee;

            private String processStatusCd;

            private String toCountryCd;

            private String fromAmount;

            private String fxTypeCd;

            private String orderTime;

            private String serviceTypeCd;

            private String fxRate;

            private String recurringTypeCd;

            private String toAccountId;

            private String fromCountryCd;

            private String processTime;

            private String userId;

            private String toCurrencyCd;

            private String serviceTypeDesc;

            private String fromCurrencyCd;

            private String fromAccountId;

            private String orderId;

            public void setDurationTypeCd(String durationTypeCd) {
                this.durationTypeCd = durationTypeCd;
            }

            public String getDurationTypeCd() {
                return this.durationTypeCd;
            }

            public void setServiceFee(String serviceFee) {
                this.serviceFee = serviceFee;
            }

            public String getServiceFee() {
                return this.serviceFee;
            }

            public void setProcessStatusCd(String processStatusCd) {
                this.processStatusCd = processStatusCd;
            }

            public String getProcessStatusCd() {
                return this.processStatusCd;
            }

            public void setToCountryCd(String toCountryCd) {
                this.toCountryCd = toCountryCd;
            }

            public String getToCountryCd() {
                return this.toCountryCd;
            }

            public void setFromAmount(String fromAmount) {
                this.fromAmount = fromAmount;
            }

            public String getFromAmount() {
                return this.fromAmount;
            }

            public void setFxTypeCd(String fxTypeCd) {
                this.fxTypeCd = fxTypeCd;
            }

            public String getFxTypeCd() {
                return this.fxTypeCd;
            }

            public void setOrderTime(String orderTime) {
                this.orderTime = orderTime;
            }

            public String getOrderTime() {
                return this.orderTime;
            }

            public void setServiceTypeCd(String serviceTypeCd) {
                this.serviceTypeCd = serviceTypeCd;
            }

            public String getServiceTypeCd() {
                return this.serviceTypeCd;
            }

            public void setFxRate(String fxRate) {
                this.fxRate = fxRate;
            }

            public String getFxRate() {
                return this.fxRate;
            }

            public void setRecurringTypeCd(String recurringTypeCd) {
                this.recurringTypeCd = recurringTypeCd;
            }

            public String getRecurringTypeCd() {
                return this.recurringTypeCd;
            }

            public void setToAccountId(String toAccountId) {
                this.toAccountId = toAccountId;
            }

            public String getToAccountId() {
                return this.toAccountId;
            }

            public void setFromCountryCd(String fromCountryCd) {
                this.fromCountryCd = fromCountryCd;
            }

            public String getFromCountryCd() {
                return this.fromCountryCd;
            }

            public void setProcessTime(String processTime) {
                this.processTime = processTime;
            }

            public String getProcessTime() {
                return this.processTime;
            }

            public void setUserId(String userId) {
                this.userId = userId;
            }

            public String getUserId() {
                return this.userId;
            }

            public void setToCurrencyCd(String toCurrencyCd) {
                this.toCurrencyCd = toCurrencyCd;
            }

            public String getToCurrencyCd() {
                return this.toCurrencyCd;
            }

            public void setServiceTypeDesc(String serviceTypeDesc) {
                this.serviceTypeDesc = serviceTypeDesc;
            }

            public String getServiceTypeDesc() {
                return this.serviceTypeDesc;
            }

            public void setFromCurrencyCd(String fromCurrencyCd) {
                this.fromCurrencyCd = fromCurrencyCd;
            }

            public String getFromCurrencyCd() {
                return this.fromCurrencyCd;
            }

            public void setFromAccountId(String fromAccountId) {
                this.fromAccountId = fromAccountId;
            }

            public String getFromAccountId() {
                return this.fromAccountId;
            }

            public void setOrderId(String orderId) {
                this.orderId = orderId;
            }

            public String getOrderId() {
                return this.orderId;
            }

        }
    }
}
